package liurong.driver.json;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.annotation.JSONField;

public class FastJsonTest {
	@Test
	public void fun1() {
		// 组装保留字段
		Map<String, String> map = new HashMap<String, String>();
		map.put("userId", "1");
		map.put("startTime", "2");
		map.put("timeZoneInfo", "3");
		map.put("roomStatus", "4");

		List<Long> currenttoids = new ArrayList<Long>();
		currenttoids.add(1234l);
		currenttoids.add(4577l);
		String jsonString = JSON.toJSONString(currenttoids);
		System.out.println(jsonString);
		map.put("currenttoids", jsonString);
		String reservedJsonStr = JSON.toJSONString(map);
		System.out.println(reservedJsonStr);

		Map<String, String> map2 = (Map<String, String>) JSON.parse(reservedJsonStr);
		String string = map2.get("currenttoids");
		System.out.println(string);
		List<Long> longList = (List<Long>) JSON.parse(string);

		System.out.println(longList);
		System.out.println(longList.size());

		String string2 = "{\"studentName\":\"刘荣1\"}";
		String string3 = "{\"student_name\":\"刘荣2\"}";

		try {
			System.out.println(JSON.parseObject(string2, Student.class));
			System.out.println(JSON.parseObject(string3, Student.class));
			System.out.println(JSON.toJSONString(JSON.parseObject(string2, Student.class)));
			System.out.println(JSON.toJSONString(JSON.parseObject(string3, Student.class)));
		} catch (Exception e) {
			e.printStackTrace();
		}

//		Student student = new Student();
//		student.setStudentName("liurong");
//		String jsonString2 = JSON.toJSONString(student);
//		System.out.println(jsonString2);
//		System.out.println(JSON.parseObject(jsonString2));
	}

}
